package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.IotEnterpriseManage;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.IotEnterpriseManageDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2021-02-20 11:33:47
 */
public class IotEnterpriseManageConverts {

    private static Logger LOG = LoggerFactory.getLogger(IotEnterpriseManageConverts.class);

    public static List<IotEnterpriseManageDTO> convert(List<IotEnterpriseManage> iotEnterpriseManageList) {
        if (CollectionUtils.isEmpty(iotEnterpriseManageList)) {
            return Collections.EMPTY_LIST;
        }

        List<IotEnterpriseManageDTO> iotEnterpriseManageListResult = Lists.newArrayList();
        for (IotEnterpriseManage iotEnterpriseManage : iotEnterpriseManageList) {
            iotEnterpriseManageListResult.add(convert(iotEnterpriseManage));
        }
        return iotEnterpriseManageListResult;
    }

    public static IotEnterpriseManageDTO convert(IotEnterpriseManage iotEnterpriseManage) {
        try {
            return BeanUtils.copy(iotEnterpriseManage, IotEnterpriseManageDTO.class);
        } catch (Exception e) {
            LOG.error("IotEnterpriseManage到IotEnterpriseManageDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "IotEnterpriseManage到IotEnterpriseManageDTO转换失败", e);
        }
    }

    public static IotEnterpriseManage convert(IotEnterpriseManageDTO iotEnterpriseManageDTO) {
        try {
            return BeanUtils.copy(iotEnterpriseManageDTO, IotEnterpriseManage.class);
        } catch (Exception e) {
            LOG.error("IotEnterpriseManageDTO到IotEnterpriseManage转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "IotEnterpriseManageDTO到IotEnterpriseManage转换失败", e);
        }
    }
}